1
|
|
|
/* eslint-disable no-useless-escape */ |
2
|
|
|
function stripTrailingSlash(str: string): string { |
3
|
|
|
return str.endsWith("/") ? str.slice(0, -1) : str; |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
function isValidUrl(str: string): boolean { |
7
|
|
|
if (str.startsWith("http://") || str.startsWith("https://")) { |
8
|
|
|
try { |
9
|
|
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars |
10
|
|
|
const url = new URL(str); |
11
|
|
|
} catch (_) { |
12
|
|
|
return false; |
13
|
|
|
} |
14
|
|
|
return true; |
15
|
|
|
} |
16
|
|
|
return false; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
export function baseUrl(): string { |
20
|
|
|
const base = document.querySelector("meta[name='base-url']"); |
21
|
|
|
if (base !== null) { |
22
|
|
|
return stripTrailingSlash(base.getAttribute("content") ?? ""); |
23
|
|
|
} |
24
|
|
|
return ""; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
export function basePathname(): string { |
28
|
|
|
const base = baseUrl(); |
29
|
|
|
return isValidUrl(base) ? new URL(baseUrl()).pathname : ""; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
export function baseApiUrl(version = 1): string { |
33
|
|
|
return `${baseUrl()}/api/v${version}`; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* |
38
|
|
|
* @param imgFile The name of the img file, not inluding the /images/ path. |
39
|
|
|
*/ |
40
|
|
|
export function imageUrl(imgFile: string): string { |
41
|
|
|
return `${baseUrl()}/images/${imgFile}`; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Removes the base url or base pathname if the given url starts with them. |
46
|
|
|
* @param url |
47
|
|
|
*/ |
48
|
|
|
export function removeBaseUrl(url: string): string { |
49
|
|
|
const base = baseUrl(); |
50
|
|
|
if (url.startsWith(base)) { |
51
|
|
|
return url.substr(base.length); |
52
|
|
|
} |
53
|
|
|
const basePath = basePathname(); |
54
|
|
|
if (url.startsWith(basePath)) { |
55
|
|
|
return url.substr(basePath.length); |
56
|
|
|
} |
57
|
|
|
return url; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
export function jobShow(locale: string, jobId: number): string { |
61
|
|
|
return `${baseUrl()}/${locale}/jobs/${jobId}`; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function applicationShow( |
65
|
|
|
locale: string, |
66
|
|
|
prefix: string, |
67
|
|
|
applicationId: number, |
68
|
|
|
jobId: number, |
69
|
|
|
): string { |
70
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applications/${applicationId}`; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function applicantShow( |
74
|
|
|
locale: string, |
75
|
|
|
prefix: string, |
76
|
|
|
applicantId: number, |
77
|
|
|
jobId: number, |
78
|
|
|
): string { |
79
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applicants/${applicantId}`; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
export function managerApplicationShow( |
83
|
|
|
locale: string, |
84
|
|
|
applicationId: number, |
85
|
|
|
jobId: number, |
86
|
|
|
): string { |
87
|
|
|
return applicationShow(locale, "manager", applicationId, jobId); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
export function managerApplicantShow( |
91
|
|
|
locale: string, |
92
|
|
|
applicantId: number, |
93
|
|
|
jobId: number, |
94
|
|
|
): string { |
95
|
|
|
return applicantShow(locale, "manager", applicantId, jobId); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
export function managerEditProfile(locale: string): string { |
99
|
|
|
return `${baseUrl()}/${locale}/manager/profile`; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
export function managerJobIndex(locale: string): string { |
103
|
|
|
return `${baseUrl()}/${locale}/manager/jobs`; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
export function managerJobSummary(locale: string, jobId: number): string { |
107
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}`; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
export function managerJobPreview(locale: string, jobId: number): string { |
111
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/preview`; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
export function managerJobApplications(locale: string, jobId: number): string { |
115
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/applications`; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
export function managerScreeningPlan(locale: string, jobId: number): string { |
119
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/assessment-plan`; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
export function applicationReviewUpdate( |
123
|
|
|
locale: string, |
124
|
|
|
applicationId: number, |
125
|
|
|
): string { |
126
|
|
|
return `${baseApiUrl()}/applications/${applicationId}/review`; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
export function jobBuilderIntro(locale: string, jobId?: number): string { |
130
|
|
|
if (jobId) { |
131
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/intro`; |
132
|
|
|
} |
133
|
|
|
return `${baseUrl()}/${locale}/manager/job-builder/intro`; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
export function jobBuilderDetails(locale: string, jobId: number): string { |
137
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/details`; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
export function jobBuilderEnv(locale: string, jobId: number): string { |
141
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/environment`; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
export function jobBuilderImpact(locale: string, jobId: number): string { |
145
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/impact`; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
export function jobBuilderTasks(locale: string, jobId: number): string { |
149
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/tasks`; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
export function jobBuilderSkills(locale: string, jobId: number): string { |
153
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/skills`; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
export function jobBuilderReview(locale: string, jobId: number): string { |
157
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/review`; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
type FaqSection = "manager-who" | "levels"; |
161
|
|
|
|
162
|
|
|
export function applicantFaq(locale: string, faqSection?: FaqSection): string { |
163
|
|
|
const base = `${baseUrl()}/${locale}/faq`; |
164
|
|
|
if (faqSection) { |
165
|
|
|
return `${base}#${faqSection}`; |
166
|
|
|
} |
167
|
|
|
return base; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
export function managerFaq(locale: string, faqSection?: FaqSection): string { |
171
|
|
|
const base = `${baseUrl()}/${locale}/manager/faq`; |
172
|
|
|
if (faqSection) { |
173
|
|
|
return `${base}#${faqSection}`; |
174
|
|
|
} |
175
|
|
|
return base; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
export function hrJobIndex(locale: string): string { |
179
|
|
|
return `${baseUrl()}/${locale}/hr/jobs`; |
180
|
|
|
} |
181
|
|
|
export function hrJobSummary(locale: string, jobId: number): string { |
182
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}`; |
183
|
|
|
} |
184
|
|
|
export function hrJobReview(locale: string, jobId: number): string { |
185
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/review`; |
186
|
|
|
} |
187
|
|
|
export function hrJobPreview(locale: string, jobId: number): string { |
188
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/preview`; |
189
|
|
|
} |
190
|
|
|
export function hrScreeningPlan(locale: string, jobId: number): string { |
191
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/assessment-plan`; |
192
|
|
|
} |
193
|
|
|
export function hrJobApplications(locale: string, jobId: number): string { |
194
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/applications`; |
195
|
|
|
} |
196
|
|
|
export const hrApplicationShow = ( |
197
|
|
|
locale: string, |
198
|
|
|
applicationId: number, |
199
|
|
|
jobId: number, |
200
|
|
|
): string => applicationShow(locale, "hr", applicationId, jobId); |
201
|
|
|
export const hrApplicantShow = ( |
202
|
|
|
locale: string, |
203
|
|
|
applicantId: number, |
204
|
|
|
jobId: number, |
205
|
|
|
): string => applicantShow(locale, "hr", applicantId, jobId); |
206
|
|
|
|
207
|
|
|
export function accountSettings(locale: string): string { |
208
|
|
|
return `${baseUrl()}/${locale}/settings`; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Converts a string to a url safe equivalent. |
213
|
|
|
* @param string Any input text. |
214
|
|
|
* @returns url safe string. |
215
|
|
|
*/ |
216
|
|
|
export function slugify(string: string): string { |
217
|
|
|
const a = |
218
|
|
|
"àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;"; |
219
|
|
|
const b = |
220
|
|
|
"aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------"; |
221
|
|
|
const p = new RegExp(a.split("").join("|"), "g"); |
222
|
|
|
|
223
|
|
|
return string |
224
|
|
|
.toString() |
225
|
|
|
.toLowerCase() |
226
|
|
|
.replace(/\s+/g, "-") // Replace spaces with - |
227
|
|
|
.replace(p, (c) => b.charAt(a.indexOf(c))) // Replace special characters |
228
|
|
|
.replace(/&/g, "-and-") // Replace & with 'and' |
229
|
|
|
.replace(/[^\w\-]+/g, "") // Remove all non-word characters |
230
|
|
|
.replace(/\-\-+/g, "-") // Replace multiple - with single - |
231
|
|
|
.replace(/^-+/, "") // Trim - from start of text |
232
|
|
|
.replace(/-+$/, ""); // Trim - from end of text |
233
|
|
|
} |
234
|
|
|
|